<template>
  <div class="main-header">
    <div class="head-container">
      <div class="htknow-logo">
        <img src="https://vitejs.cn/logo.svg" alt />
        <span>vite2</span>
      </div>
      <div class="head-menu-right">
        <el-dropdown>
          <img class="head-portrait" src="../assets/" alt />
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>修改资料</el-dropdown-item>
              <el-dropdown-item @click="handleClearAccount">退出账号</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
import { clearALLStorage } from '../plugins/storege'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
export default {
  setup() {
    const store = useStore()
    const Router = useRouter()
    const handleClearAccount = () => {
      // 清除缓存数据 跳转到登录页面
      clearALLStorage()
      store.commit('SET_TOKEN', '')
      Router.push('/login')
    }
    return {
      handleClearAccount,
    }
  },
}
</script>

<style scoped lang="scss">
.main-header {
  width: 100%;
  height: 80px;
  background: #fff;
  box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9;
  .head-container {
    width: var(--mainWidth);
    margin: 0 auto;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .htknow-logo {
      width: 240px;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        width: 40px;
        height: 40px;
      }
      span {
        font-size: 14px;
        margin-left: 8px;
        color: #5d9aff;
      }
    }
    .head-menu-right {
      display: flex;
      align-items: center;
      .iconfont {
        margin-right: 20px;
      }
      .head-portrait {
        width: 38px;
        height: 38px;
        border-radius: 50%;
      }
    }
  }
}
</style>
